package com.hzqy.service.weatherForecast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.hzqy.persistence.dao.weatherForecast.WeatherForecastDao;
import com.hzqy.web.vo.weatherForecast.WeatherForecastVo;

@Service
public class WeatherForecastServiceBean {
	private static final long serialVersionUID = 1L;
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	
	@Resource
	private WeatherForecastDao weatherForecastDao;
	
	
	public Map<String,Object> insertWeather(WeatherForecastVo weatherForecastVo){
		Map<String,Object> resultMap = new HashMap<String,Object>();
		int flag = 0;
		if(weatherForecastVo==null ) {
			flag = -1;
		}
		if(flag==0){
			weatherForecastDao.insertWeather(weatherForecastVo);
			resultMap.put("success", true);
			resultMap.put("result","新增天气成功!");
		}
		return resultMap;
	}

	
	/**
	 * 列表获取
	 * @param WeatherForecastVo
	 * @param curPage
	 * @param pageSize
	 * @return
	 */
	public Map<String,Object> selectWeatherList(WeatherForecastVo weatherForecastVo, int curPage,int pageSize) {
			
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = weatherForecastDao.findWeatherCount(weatherForecastVo);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("f_wf_startTime", weatherForecastVo.getF_wf_startTime());
			map.put("f_wf_endTime", weatherForecastVo.getF_wf_endTime());
			map.put("f_wf_userarea", weatherForecastVo.getF_wf_userarea());
			map.put("f_wf_cityid",weatherForecastVo.getF_wf_cityid());
			List<WeatherForecastVo> results = weatherForecastDao.findWeatherList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<WeatherForecastVo>());
		}
		return map;
	}
	
	public WeatherForecastVo selectWeather(WeatherForecastVo weatherForecastVo) {
		return  weatherForecastDao.selectWeather(weatherForecastVo);
	}
	public int updateWeather(WeatherForecastVo weatherForecastVo) {
		return  weatherForecastDao.updateWeather(weatherForecastVo);
	}
	public int deleteWeather(int f_wf_id) {
		return weatherForecastDao.deleteWeather(f_wf_id);
	}
}
